using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour
{
    public IsEnemyDie IsEnemyDie;
    private void Awake()
    {
        EventManager.Instance.Register<bool>(EventName.GameOverEvent, GameOver);
    }

    private void OnDestroy()
    {
        EventManager.Instance.Unregister<bool>(EventName.GameOverEvent, GameOver);
    }

    private void GameOver(bool obj)
    {
        gameObject.SetActive(false);
    }

    public void Init()
    {
        IsEnemyDie.Init();
    }

    /// <summary>
    /// 玩家死亡
    /// </summary>
    /// <param name="collision"></param>
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Player") && !IsEnemyDie.isdie)
        {
            Debug.Log("玩家死亡");
            if (!GameManager.Instance.isHaveDun)
            {
                EventManager.Instance.Send<bool>(EventName.GameOverEvent, true);
            }
            else
            {
                GameManager.Instance.isHaveDun = false;
                Debug.Log("Enemy");
                IsEnemyDie.EnemyDie();
            }
        }
    }
}
